<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>详情</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
	<style type="text/css">
	.layui-table td, .layui-table th{
	    padding: 3px 5px;
	}
	.fieldInput {
		width:80px;
	}
	.filedSelect{
	display: block;
	}
	</style>
</head>
<body>
       <div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-card-body"> 
          
          <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="margin-top: 20px;margin-bottom:50px;" >
 <ul class="layui-tab-title">
    <li class="layui-this">数据库信息</li>
    <li>表生成配置</li>
  </ul>
          
<!--  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;margin-bottom:50px;">
  <legend>详情</legend>
</fieldset> -->
<div class="layui-tab-content">
    <div class="layui-tab-item layui-show">
    
	<input type="hidden" id="id" value="<#if databaseDTO??>${databaseDTO.id}<#else></#if>" >
 <div class="layui-form">
  <table class="layui-table">
    <colgroup>
      <col width="150">
      <col>
      <col width="150">
      <col>
      <col width="150">
      <col>
    </colgroup>
    <tbody>
      	<tr>
        <th>数据库名称</th>
		<td><#if databaseDTO.dbName??>${ databaseDTO.dbName! }</#if></td>
        <th>驱动</th>
		<td><#if databaseDTO.dbDriverName??>${ databaseDTO.dbDriverName! }</#if></td>
        <th>端口号</th>
		<td><#if databaseDTO.dbPort??>${ databaseDTO.dbPort! }</#if></td>
	      </tr>
      	<tr>
        <th>用户名</th>
		<td><#if databaseDTO.dbUserName??>${ databaseDTO.dbUserName! }</#if></td>
        <th>密码</th>
		<td><#if databaseDTO.dbPassword??>${ databaseDTO.dbPassword! }</#if></td>
        <th>数据库类型</th>
		<td><#if databaseDTO.dbType??>${dictMap['db_type'][databaseDTO.dbType]}</#if></td>
	      </tr>
	      <tr>
	      <th>数据库链接</th>
	      <td colspan="5" >${databaseDTO.dbHost}</td>
	      </tr>
    </tbody>
  </table>
</div>
  

 <div class="layui-form-item" style="margin-top: 20px;margin-bottom:50px;">
	 	<a class="layui-btn linksAdd_btn" style="background-color:#5FB878" href="javascript:void(0);" onclick="addTableData('${databaseDTO.id}','');">添加</a>
		<button type="button" class="layui-btn layui-btn-primary" onclick="backList();" >返回</button>
  </div>
  
  <div class="layui-form member_list" style="margin-top: 20px;margin-bottom:50px;" >
	  	<table class="layui-table">
		    <colgroup>
				<col>
				<col>
				<col>
				<col>
				<col>
		    </colgroup>
		    <thead>
				<tr>
					<th>序号</th>
					<th>表名</th>
					<th>表id类型</th>
					<th>包名</th>
					<th>前缀</th>
					<th>作者</th>
					<!--   <th>输出地址</th> -->
					<!--   <th>公共字段</th> -->
					<!--   <th>父包</th> -->
					<!--   <th>实体包名称</th> -->
					<!--   <th>service包名</th> -->
					<!--   <th>impl包名</th> -->
					<!--   <th>dao包名</th> -->
					<!--   <th>xml包名</th> -->
					<!--   <th>controller包名</th> -->
					<th>创建时间</th>
					<th>操作</th>
				</tr>
		    </thead>
		    <tbody>
		    	<#list result as data>
		    	<tr>
					<td>${data_index+1}</td>
							<td><#if data.tableName??>${data.tableName!}</#if></td>
							<td><#if data.tableIdType??>${data.tableIdType!}</#if></td>
							<td><#if data.packageName??>${data.packageName!}</#if></td>
							<td><#if data.prefix??>${data.prefix!}</#if></td>
					<td><#if data.author??>${data.author! }</#if></td>
					<!--  <td><#if data.outPutDir??>${data.outPutDir! }</#if></td>-->
					<!--  <td><#if data.commonColumns??>${data.commonColumns! }</#if></td>-->
					<!--  <td><#if data.parentPackage??>${data.parentPackage! }</#if></td>-->
					<!--  <td><#if data.entityPackage??>${data.entityPackage! }</#if></td>-->
					<!--  <td><#if data.servicePackage??>${data.servicePackage! }</#if></td>-->
					<!--  <td><#if data.serviceImplPackage??>${data.serviceImplPackage! }</#if></td>-->
					<!--  <td><#if data.mapperPackage??>${data.mapperPackage! }</#if></td>-->
					<!--  <td><#if data.xmlPackage??>${data.xmlPackage! }</#if></td>-->
					<!--  <td><#if data.controllerPackage??>${data.controllerPackage! }</#if></td>-->
					<td>${data.createTime?datetime}</td>
					<td><a class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:void(0);" onclick="addTableData('${databaseDTO.id}','${data.id}');" ><i class="iconfont icon-edit"></i>修改</a>
					<a class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:void(0);" onclick="showDetial('${data.id}');" ><i class="iconfont"></i>详情</a> 
		        	<a class="layui-btn layui-btn-danger layui-btn-xs" href="javascript:void(0);" onclick="del('${data.id}');" ><i class="layui-icon"></i>删除</a>
		        	</td>
				</tr>
				</#list>
			</tbody>
		</table>
	</div>
  
  
  </div>
    <div class="layui-tab-item">
    <form id="searchForm" class="layui-form layui-form-pane" method="post" action=""  >
    	<div class="layui-inline">
	    <label class="layui-form-label">表名称</label>
	    <div class="layui-input-inline">
	    	<select name="tableName" id="tableName" lay-filter="tableChange" >
	    	<#list result as data>
	    	<option  value="${data.tableName}" >${data.tableName}</option>
	    	</#list>
	    	</select>
	    </div>
	  </div>
	  <div class="layui-inline">
		    <a style="background-color:#5FB878" id="nextTableATag"  class="layui-btn search_btn" onclick="nextTable();" >下一步</a>
		    <a  class="layui-btn search_btn" id="toCreateCode" style="display:none;" onclick="saveTableInfo();" >保存并生成代码</a>
		</div>
	  </form>
	  
	  <div class="layui-form member_list" id="tableInfoDiv" >
	  </div>
	  
    
    </div>
	
	</div>
	</div>
  
  
	</div>
	</div>
	</div>
<script src="${resRoot}/layui/layui.js" charset="utf-8"></script>
<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
<script src="${resRoot}/layui/layui.all.js" charset="utf-8"></script>
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
	  var form = layui.form
	  ,layer = layui.layer,
	  $ = layui.jquery,
	  element = layui.element; 


	  form.on('select(tableChange)', function(data){
		  var value = data.value;
		  $("#tableInfoDiv").html("");
			$("#toCreateCode").hide();
			$("#nextTableATag").show();
		  });
});
function backList() {
	layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

function nextTable() {
	var tableName = $("#tableName").val();
	var dbId = $("#id").val();
	$.ajax({
		type : "post",
		url : "${base}/sys/tableInfo/getTableFields",
		data : {
			tableName : tableName,
			dbId : dbId
			},
		dataType : "text",
		async : false,
		success : function(data) {
			if(data!="") {
				console.log(data)
				$("#tableInfoDiv").html(data);
				$("#toCreateCode").show();
				$("#nextTableATag").hide();
			}
		}
	}); 
}

function saveTableInfo() {
	var fields = $.parseJSON($("#fields").val());
	console.log(fields);
	for(var i = 0;i< fields.length;i++) {
	var comment = $("#" + fields[i].name + "_comment").val();
	var htmlType = $("#" + fields[i].name + "_htmlType").val();
	var dictValue = $("#" + fields[i].name + "_dictValue").val();
	var maxLength = $("#" + fields[i].name + "_maxLength").val();
	var propertyType = $("#" + fields[i].name +"_propertyType").val();
	// var notNull = $("#" + fields[i].name + "_notNull").val();
	// var isShow = $("#" + fields[i].name + "_isShow").val();
	var notNull = $("input:checked[id=" + fields[i].name + "_notNull" + "]").val();
	if(notNull==""|| notNull=="undefined" || notNull==null) {
		notNull="0"
	}
	var isShow = $("input:checked[id=" + fields[i].name + "_isShow" + "]").val();
	if(isShow==""|| isShow=="undefined" || isShow==null) {
		isShow="0"
	}
	var isSelect=$("input:checked[id=" + fields[i].name + "_isSelect" + "]").val();
	if(isSelect==""|| isSelect=="undefined" || isSelect==null) {
		isSelect="0"
	}
	fields[i].comment = comment;
	fields[i].htmlType = htmlType;
	fields[i].dictValue = dictValue;
	fields[i].maxLength = maxLength;
	fields[i].notNull = notNull;
	fields[i].isShow = isShow;
	fields[i].propertyType = propertyType;
	fields[i].isSelect = isSelect;
		}
	console.log(fields);
	var tableName = $("#tableName").val();
	var dbId = $("#id").val();
	$.ajax({
		type : "post",
		url : "${base}/sys/fieldInfo/saveList",
		data : {
			tableName : tableName,
			dbId : dbId,
			fields : JSON.stringify(fields)
			},
		dataType : "text",
		async : false,
		success : function(data) {
			if(data.message=="1") {
				layer.alert("生成成功")
				console.log(data)
				// $("#tableInfoDiv").html(data);
				// $("#toCreateCode").show();
			}
		}
	}); 
}

function addTableData(dbId,id){
		var url = "${base}/sys/tableInfo/input?dbId=" + dbId;
		var titleStr = "添加";
		if(id){
			url = url + "&id=" + id;
			titleStr = "修改";
		}
      var index = layui.layer.open({
          title : titleStr,
          type : 2,
          content : url,
          success : function(layero, index){
              var body = layui.layer.getChildFrame('body', index);
              setTimeout(function(){
                  layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                      tips: 3
                  });
              },500)
          }
      })
      layui.layer.full(index);
      //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
      $(window).on("resize",function(){
          layui.layer.full(index);
      })
  }
  
function del(id){	
		layer.confirm('确定删除该条数据吗?', function(index){
		 $.ajax({
  		 type : "post",
  		 url : "${base}/sys/tableInfo/del",
  		 data : {
  			  id : id
  			 },
			 dataType : "json",
			 async : false,
			 success : function(data) {
				 flag  = data.message;
					if(flag != 0) {
						layer.msg('删除成功！', {
							  icon: 1,
							  time: 2000 //2秒关闭（如果不配置，默认是3秒）
							}, function(){
							  //do something
								window.location.reload();
							});  

						
					} else {
						layer.alert("数据错误，请完善数据！");
					}
			 }
  	 });
	});
}
</script>
</body>
</html>